package com.xyj.listener;

import com.xyj.action.RepairAction;
import com.xyj.service.RepairServiceI;
import com.xyj.util.LoggerUtil;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.*;

/**
 * Created by 徐宇健 on 2015/2/14 0014.
 */
public class repairListener implements ServletContextListener,ServletContextAttributeListener,HttpSessionListener,  HttpSessionAttributeListener {

    @Override
    public void attributeAdded(ServletContextAttributeEvent servletContextAttributeEvent) {

    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) {

    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent servletContextAttributeEvent) {

    }

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        LoggerUtil.getLogger().info("初始化APP.....");
        WebApplicationContext  ctx = WebApplicationContextUtils.getWebApplicationContext(servletContextEvent.getServletContext());
        RepairServiceI repairAction = (RepairServiceI) ctx.getBean("repairService");
        repairAction.repair();
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }

    @Override
    public void attributeAdded(HttpSessionBindingEvent httpSessionBindingEvent) {

    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent httpSessionBindingEvent) {

    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent httpSessionBindingEvent) {

    }

    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {

    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {

    }


}
